class Solution(object):
    def numRescueBoats(self, people, limit):
        people.sort()
        left = 0
        right = len(people) - 1
        c = 0
        while left < right:
            if people[left] + people[right] <= limit:
                left += 1
                right -= 1
            else:
                right -= 1
            c += 1
        if left == right:
            c += 1
        return c



data = Solution()
people = [3, 2, 2, 1]
limit = 3
print(data.numRescueBoats(people, limit))
